Skip to content

Group event notifications and inbound nukes in quick succession#4530

Open
blontd6 wants to merge 2 commits into
openfrontio:mainfrom
blontd6:feature/group-event-messages
Open

Group event notifications and inbound nukes in quick succession#4530
blontd6 wants to merge 2 commits into
openfrontio:mainfrom
blontd6:feature/group-event-messages

Conversation

@blontd6

@blontd6 blontd6 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Add approved & assigned issue number here:

Resolves #4516

Description:

Restores real-time event notifications for structure capture, loss, and destruction (such as Cities, Ports, Silos, Factories, SAM Launchers, and Defense Posts), and aggregates these notifications alongside inbound atomic bombs, hydrogen bombs, and MIRVs when they occur in quick succession (within a 3-second / 30-tick window).
formats such as:

  • "Your 4 Cities were destroyed"
  • "Captured 4 Cities from [Player]"
  • "[Player] - 3 atom bombs inbound"

This provides clear, concise, and immediate tactical feedback to players in high-stress combat moments without sacrificing important event tracking.

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory

Please put your Discord username so you can be contacted if a bug or regression is found:

blontd6

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ce2c1830-0fed-4017-86ff-862c6b0af7ce

📥 Commits

Reviewing files that changed from the base of the PR and between e2fd466 and faac666.

📒 Files selected for processing (2)
  • resources/lang/en.json
  • src/client/hud/layers/EventsDisplay.ts
✅ Files skipped from review due to trivial changes (1)
  • resources/lang/en.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/client/hud/layers/EventsDisplay.ts

Walkthrough

Adds grouped and pluralized event notifications for repeated destroyed, captured, lost, and inbound nuke messages. Localization strings were expanded, EventsDisplay now aggregates matching events, and UnitImpl now emits structure-specific capture/loss messages and includes structures in delete-message display handling.

Changes

Event grouping feature

Layer / File(s) Summary
Localization strings for grouped/plural events
resources/lang/en.json
Adds inbound atom, hydrogen, and MIRV message variants plus captured, destroyed, and lost unit strings, along with plural unit type labels.
GameEvent grouping model and aggregation
src/client/hud/layers/EventsDisplay.ts
Extends GameEvent with grouping fields, adds translation and inbound-warning parsing helpers, and updates addEvent to merge matching events within a 30-tick window and rebuild the description.
Wiring groupKey into unit and nuke event handlers
src/client/hud/layers/EventsDisplay.ts
onDisplayMessageEvent derives grouping metadata for destroyed/captured/lost messages; onUnitIncomingEvent parses inbound nuke text into grouped event metadata before calling addEvent.
Structure-specific capture/loss/destroyed messages
src/core/game/UnitImpl.ts
Imports Structures; setOwner emits unit_captured and unit_lost for structures; displayMessageOnDeleted now also allows structures.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant UnitImpl
  participant EventsDisplay
  participant addEvent
  participant EventLog

  UnitImpl->>EventsDisplay: emit unit_captured / unit_lost / unit_destroyed
  EventsDisplay->>EventsDisplay: derive groupKey, unitType, targetPlayerName
  EventsDisplay->>addEvent: pass event with grouping data
  addEvent->>EventLog: search same groupKey within 30 ticks
  alt match found
    addEvent->>EventLog: increment count and refresh description
  else no match
    addEvent->>EventLog: append new row
  end
Loading

Suggested labels: Translation

Suggested reviewers: evanpelle

Poem

A city falls, then falls again,
the log no longer chants in pain.
One tidy line for many sparks,
one grouped alert that marks the marks.
Nukes inbound, the count grows clear,
less clutter now is finally here.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: grouping event notifications and inbound nukes into quick successive batches.
Description check ✅ Passed The description is clearly related to grouped structure and inbound nuke notifications, matching the changeset.
Linked Issues check ✅ Passed The PR implements 30-tick grouping for structure events and inbound nukes, which satisfies issue #4516.
Out of Scope Changes check ✅ Passed The changes stay focused on event grouping, translation strings, and related display logic, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/client/hud/layers/EventsDisplay.ts (1)

37-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Fragile string parsing with magic offsets.

parseInboundNuke reverse-engineers the player name from hardcoded lengths (-20, -24, 7, -22) of the exact English message. If any of these strings change (or the message is localized), the slice silently returns the wrong name or null, and grouping quietly stops working. The MIRV offsets are especially error-prone because each ⚠️ is 2 UTF-16 units.

Cleaner option: pass the nuke type and player name as structured fields on the incoming event so no string parsing is needed. If parsing must stay, at least compute offsets from the suffix constants instead of literals:

♻️ Derive offsets from the suffix strings
 function parseInboundNuke(m: string): { player: string; nukeType: string } | null {
-  if (m.endsWith(" - atom bomb inbound")) return { player: m.slice(0, -20), nukeType: "atom" };
-  if (m.endsWith(" - hydrogen bomb inbound")) return { player: m.slice(0, -24), nukeType: "hydrogen" };
-  if (m.startsWith("⚠️⚠️⚠️ ") && m.endsWith(" - MIRV INBOUND ⚠️⚠️⚠️")) return { player: m.slice(7, -22), nukeType: "mirv" };
+  const atom = " - atom bomb inbound";
+  const hydrogen = " - hydrogen bomb inbound";
+  const mirvPre = "⚠️⚠️⚠️ ";
+  const mirvSuf = " - MIRV INBOUND ⚠️⚠️⚠️";
+  if (m.endsWith(atom)) return { player: m.slice(0, -atom.length), nukeType: "atom" };
+  if (m.endsWith(hydrogen)) return { player: m.slice(0, -hydrogen.length), nukeType: "hydrogen" };
+  if (m.startsWith(mirvPre) && m.endsWith(mirvSuf)) return { player: m.slice(mirvPre.length, -mirvSuf.length), nukeType: "mirv" };
   return null;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/client/hud/layers/EventsDisplay.ts` around lines 37 - 42, The
parseInboundNuke helper is relying on fragile hardcoded slice offsets to recover
the player name from event text. Update EventsDisplay.parseInboundNuke to avoid
magic numbers by either passing structured player/nuke fields into the event
handling path, or by deriving the start/end offsets from the exact suffix
strings used in each message pattern. Keep the existing function and its MIRV
branch, but make the parsing length-safe so changes to the message text or
Unicode characters do not break grouping.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/client/hud/layers/EventsDisplay.ts`:
- Line 35: The pluralizeUnit helper in EventsDisplay hardcodes English plural
forms, so update it to use the translated unit-name keys from the language
resources instead of deriving text from the raw enum string. Locate the
pluralization logic in pluralizeUnit and switch it to resolve the appropriate
unit.* entries from the i18n layer so event text stays locale-safe.

---

Nitpick comments:
In `@src/client/hud/layers/EventsDisplay.ts`:
- Around line 37-42: The parseInboundNuke helper is relying on fragile hardcoded
slice offsets to recover the player name from event text. Update
EventsDisplay.parseInboundNuke to avoid magic numbers by either passing
structured player/nuke fields into the event handling path, or by deriving the
start/end offsets from the exact suffix strings used in each message pattern.
Keep the existing function and its MIRV branch, but make the parsing length-safe
so changes to the message text or Unicode characters do not break grouping.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 24d4b3ef-03e5-4da4-a2fa-e002f60f946c

📥 Commits

Reviewing files that changed from the base of the PR and between 1db65a1 and 4e80a47.

📒 Files selected for processing (3)
  • resources/lang/en.json
  • src/client/hud/layers/EventsDisplay.ts
  • src/core/game/UnitImpl.ts

Comment thread src/client/hud/layers/EventsDisplay.ts Outdated
@github-project-automation github-project-automation Bot moved this from Triage to Development in OpenFront Release Management Jul 8, 2026
@blontd6 blontd6 force-pushed the feature/group-event-messages branch from f25a559 to e2fd466 Compare July 8, 2026 01:54
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 8, 2026
@evanpelle

Copy link
Copy Markdown
Collaborator

looks like the CI is failing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Development

Development

Successfully merging this pull request may close these issues.

Group captured/destroyed structures and inbound nuke notifications to reduce clutter

2 participants